package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.base.BaseModel;
import com.sphd.beautysalon.info.VipInfo;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.sphd.beautysalon.presenter.RechargePresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2017/01/19
*/

public class RechargeModelImpl implements RechargeModel{

    @Override
    public void sendUrl(String url, RechargePresenterImpl rechargePresenter) {
        BaseModel.volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    double daytopup=response.getDouble("daytopup");
                    double alltopup=response.getDouble("alltopup");
                    List<VipInfo> vipInfos = JsonUtil.getListFromString(response.getString("res"),VipInfo.class);
                    rechargePresenter.recRes(daytopup,alltopup,vipInfos);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                rechargePresenter.sendError(error);
            }
        });
    }
}